package com.yanxu.design01_singleton.destroy.reflection_destory;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2025/4/14-2025
 * @Description: 这里用一句话描述这个类的作用
 */
public class HungryInstance_Fixed {
    private static HungryInstance_Fixed hungryInstance = new HungryInstance_Fixed();

    private HungryInstance_Fixed() {
        /*
        * 反射防御增强代码
        * 因为单例对象在类加载的时候就已经创建了。所以在利用反射调用构造方法的时候，hungryInstance就已经不为 null 了。
        * */
        if (hungryInstance != null) {
            throw new RuntimeException("hungryInstance not allow reflection create!!!");
        }
    }

    public static HungryInstance_Fixed getInstance() {
        return hungryInstance;
    }
}